package com.yy.hi.app.demo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Environment
import android.view.View
import com.yy.hi.app.R
import com.yy.hi.library.hilog.HiFilePrinter
import com.yy.hi.library.hilog.HiLog
import com.yy.hi.library.hilog.HiLogConfig
import com.yy.hi.library.hilog.HiLogManager
import com.yy.hi.library.hilog.HiLogType
import com.yy.hi.library.hilog.HiViewPrinter
import java.io.File

class HiLogDemoActivity : AppCompatActivity() {
    var viewPrinter: HiViewPrinter? = null
    val filePrinter by lazy {
        HiFilePrinter.getInstance(
            Environment.getExternalStorageDirectory().absolutePath + File.separator +
                packageName + File.separator + "logs ",
            1000L * 60);
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_hi_log_demo)
        viewPrinter = HiViewPrinter(this)

        findViewById<View>(R.id.btn).setOnClickListener {
            printLog()
        }
        viewPrinter!!.hiViewPrinterProvider.showFloatingView()
    }

    private fun printLog() {
        HiLogManager.getInstance().addPrinter(viewPrinter)
        HiLogManager.getInstance().addPrinter(filePrinter)
        HiLog.log(object : HiLogConfig() {
            override fun includeThread(): Boolean {
                return true
            }

            override fun stackTraceDepth(): Int {
                return 0
            }
        }, HiLogType.E, "----", "5566");
        HiLog.a("9900")
    }
}
